home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / orbits / sgp4_pl2 / sgp_in.pas < prev    next >
Pascal/Delphi Source File  |  1992-09-13  |  13KB  |  447 lines

  1. Unit SGP_In;  (** This unit contains machine-specific code **)
  2. {           Author:  Dr TS Kelso }
  3. { Original Version:  1992 Jun 25 }
  4. { Current Revision:  1992 Sep 13 }
  5. {          Version:  2.00 }
  6. {        Copyright:  1992, All Rights Reserved }
  7. {$N+}
  8.  
  9. INTERFACE
  10.   Uses SGP_Math,SGP_Init,Support;
  11.  
  12. const
  13.   data_type : byte = 3;
  14.  
  15. var
  16.   fsat,fobs : text;
  17.  
  18. Procedure Select_Time(message : string;
  19.                     xpos,ypos : byte;
  20.                   var default : time_set;
  21.                     precision : byte);
  22. Procedure Select_Time_Interval(message : string;
  23.                              xpos,ypos : byte;
  24.                            var default : time_set;
  25.                              precision : byte);
  26. Function Checksum_Good(line : line_data) : boolean;
  27. Function Good_Elements(line : two_line) : boolean;
  28. Procedure Input_Satellite(index : word);
  29. Function Input_Satellite_Data(fn : string) : word;
  30. Procedure Select_Satellites(title : string;
  31.                           x,y,w,h : byte;
  32.                            number : word);
  33. Procedure Input_Observer(var geodetic : vector);
  34.  
  35. IMPLEMENTATION
  36.   Uses CRT,DOS,MinMax;
  37.  
  38. var
  39.   i : byte;
  40.  
  41. Procedure Echo_Time(time : time_set;
  42.           item,precision : byte);
  43.   begin
  44.   GotoXY(2,1);
  45.   ClrEOL;
  46.   if item = 1 then ReverseVideo;
  47.   Write(time.yr);  NormalVideo;
  48.   Write(' ');
  49.   if item = 2 then ReverseVideo;
  50.   Write(Copy('  JanFebMarAprMayJunJulAugSepOctNovDec',3*time.mo,3));
  51.   NormalVideo;
  52.   Write(' ');
  53.   if item = 3 then ReverseVideo;
  54.   Write(TwoDigit(time.dy));
  55.   NormalVideo;
  56.   if precision > 3 then
  57.     begin
  58.     Write('  ');
  59.     if item = 4 then ReverseVideo;
  60.     Write(TwoDigit(time.hr));
  61.     NormalVideo;
  62.     end; {if}
  63.   if precision > 4 then
  64.     begin
  65.     Write(':');
  66.     if item = 5 then ReverseVideo;
  67.     Write(TwoDigit(time.mi));
  68.     NormalVideo;
  69.     end; {if}
  70.   if precision > 5 then
  71.     begin
  72.     Write(':');
  73.     if item = 6 then ReverseVideo;
  74.     Write(TwoDigit(time.se));
  75.     NormalVideo;
  76.     end; {if}
  77.   if precision > 6 then
  78.     begin
  79.     Write('.');
  80.     if item = 7 then ReverseVideo;
  81.     Write(TwoDigit(time.hu));
  82.     NormalVideo;
  83.     end; {if}
  84.   end; {Procedure Echo_Time}
  85.  
  86. Procedure Update_Field(choice : char;
  87.                     var value : word;
  88.                     llim,ulim : word;
  89.                       var pos : byte;
  90.                     lpos,upos : byte);
  91.   begin
  92.   case choice of
  93.       Up : value := IMin(value+1,ulim);
  94.       Dn : value := IMax(value-1,llim);
  95.     Home : value := llim;
  96.     Endd : value := ulim;
  97.       Lt : pos := IMax(lpos,pos-1);
  98.       Rt : pos := IMin(pos+1,upos);
  99.     end; {case}
  100.   end; {Procedure Update_Field}
  101.  
  102. Procedure Select_Time(message : string;
  103.                     xpos,ypos : byte;
  104.                   var default : time_set;
  105.                     precision : byte);
  106.   const
  107.     days : array [0..1,1..12] of byte
  108.          = ((31,28,31,30,31,30,31,31,30,31,30,31),
  109.             (31,29,31,30,31,30,31,31,30,31,30,31));
  110.   var
  111.     pos,w     : byte;
  112.     choice    : char;
  113.     llim,ulim : array [1..7] of word;
  114.   Function LY(year : word) : byte;
  115.     begin
  116.     if (year mod 4 = 0) and
  117.        ((year mod 100 <> 0) or (year mod 400 = 0)) then
  118.       LY := 1
  119.     else
  120.       LY := 0;
  121.     end; {Function LY}
  122.   begin
  123.   Cursor_Off;
  124.   precision := IMin(IMax(3,precision),7);
  125.   case precision of
  126.     3 : w := 13;
  127.     4 : w := 17;
  128.     5 : w := 20;
  129.     6 : w := 23;
  130.     7 : w := 26;
  131.     end; {case}
  132.   if precision < 7 then
  133.     default.hu := 0;
  134.   if precision < 6 then
  135.     default.se := 0;
  136.   if precision < 5 then
  137.     default.mi := 0;
  138.   if precision < 4 then
  139.     default.hr := 0;
  140.   MakeWindow(xpos,ypos,w,1,white,message);
  141.   llim[1] := 1957;  ulim[1] := 2200;
  142.   llim[2] :=    1;  ulim[2] :=   12;
  143.   llim[3] :=    1;  ulim[3] := days[LY(default.yr),default.mo];
  144.   llim[4] :=    0;  ulim[4] :=   23;
  145.   llim[5] :=    0;  ulim[5] :=   59;
  146.   llim[6] :=    0;  ulim[6] :=   59;
  147.   llim[7] :=    0;  ulim[7] :=   99;
  148.   pos := 1;
  149.   Echo_Time(default,pos,precision);
  150.   repeat
  151.     choice := ReadKey;
  152.     if choice = #00 then
  153.       begin
  154.       choice := ReadKey;
  155.       if choice in [Up,Dn,Home,Endd,Lt,Rt] then
  156.         begin
  157.         case pos of
  158.           1 : Update_Field(choice,default.yr,llim[pos],ulim[pos],pos,1,precision);
  159.           2 : Update_Field(choice,default.mo,llim[pos],ulim[pos],pos,1,precision);
  160.           3 : Update_Field(choice,default.dy,llim[pos],ulim[pos],pos,1,precision);
  161.           4 : Update_Field(choice,default.hr,llim[pos],ulim[pos],pos,1,precision);
  162.           5 : Update_Field(choice,default.mi,llim[pos],ulim[pos],pos,1,precision);
  163.           6 : Update_Field(choice,default.se,llim[pos],ulim[pos],pos,1,precision);
  164.           7 : Update_Field(choice,default.hu,llim[pos],ulim[pos],pos,1,precision);
  165.           end; {case}
  166.         ulim[3] := days[LY(default.yr),default.mo];
  167.         if default.dy > ulim[3] then
  168.           default.dy := ulim[3];
  169.         Echo_Time(default,pos,precision);
  170.         end; {if}
  171.       end; {if}
  172.   until choice = ^M;
  173.   MakeWindow(xpos,ypos,w,1,lightgray,message);
  174.   Echo_Time(default,0,precision);
  175.   Window(1,1,80,25);
  176.   end; {Procedure Input_Time}
  177.  
  178. Procedure Echo_Time_Interval(time : time_set;
  179.                    item,precision : byte);
  180.   begin
  181.   GotoXY(5,2);
  182.   ClrEOL;
  183.   if item = 3 then ReverseVideo;
  184.   Write(time.dy);
  185.   NormalVideo;
  186.   if precision > 3 then
  187.     begin
  188.     Write('  ');
  189.     if item = 4 then ReverseVideo;
  190.     Write(TwoDigit(time.hr));
  191.     NormalVideo;
  192.     end; {if}
  193.   if precision > 4 then
  194.     begin
  195.     Write(':');
  196.     if item = 5 then ReverseVideo;
  197.     Write(TwoDigit(time.mi));
  198.     NormalVideo;
  199.     end; {if}
  200.   if precision > 5 then
  201.     begin
  202.     Write(':');
  203.     if item = 6 then ReverseVideo;
  204.     Write(TwoDigit(time.se));
  205.     NormalVideo;
  206.     end; {if}
  207.   if precision > 6 then
  208.     begin
  209.     Write('.');
  210.     if item = 7 then ReverseVideo;
  211.     Write(TwoDigit(time.hu));
  212.     NormalVideo;
  213.     end; {if}
  214.   end; {Procedure Echo_Time_Interval}
  215.  
  216. Procedure Select_Time_Interval(message : string;
  217.                              xpos,ypos : byte;
  218.                            var default : time_set;
  219.                              precision : byte);
  220.   var
  221.     pos,w     : byte;
  222.     choice    : char;
  223.     llim,ulim : array [1..7] of word;
  224.   begin
  225.   Cursor_Off;
  226.   precision := IMin(IMax(3,precision),7);
  227.   case precision of
  228.     3 : w :=  5;
  229.     4 : w :=  9;
  230.     5 : w := 12;
  231.     6 : w := 15;
  232.     7 : w := 18;
  233.     end; {case}
  234.   if precision < 7 then
  235.     default.hu := 0;
  236.   if precision < 6 then
  237.     default.se := 0;
  238.   if precision < 5 then
  239.     default.mi := 0;
  240.   if precision < 4 then
  241.     default.hr := 0;
  242.   MakeWindow(xpos,ypos,IMax(w+1,13),2,white,message);
  243.   Write(Copy(' days  hr:mn:sc.hu',1,w));
  244.   llim[3] := 0;  ulim[3] :=  9;
  245.   llim[4] := 0;  ulim[4] := 23;
  246.   llim[5] := 0;  ulim[5] := 59;
  247.   llim[6] := 0;  ulim[6] := 59;
  248.   llim[7] := 0;  ulim[7] := 99;
  249.   pos := 3;
  250.   Echo_Time_Interval(default,pos,precision);
  251.   repeat
  252.     choice := ReadKey;
  253.     if choice = #00 then
  254.       begin
  255.       choice := ReadKey;
  256.       if choice in [Up,Dn,Home,Endd,Lt,Rt] then
  257.         begin
  258.         case pos of
  259.           3 : Update_Field(choice,default.dy,llim[pos],ulim[pos],pos,3,precision);
  260.           4 : Update_Field(choice,default.hr,llim[pos],ulim[pos],pos,3,precision);
  261.           5 : Update_Field(choice,default.mi,llim[pos],ulim[pos],pos,3,precision);
  262.           6 : Update_Field(choice,default.se,llim[pos],ulim[pos],pos,3,precision);
  263.           7 : Update_Field(choice,default.hu,llim[pos],ulim[pos],pos,3,precision);
  264.           end; {case}
  265.         Echo_Time_Interval(default,pos,precision);
  266.         end; {if}
  267.       end; {if}
  268.   until choice = ^M;
  269.   MakeWindow(xpos,ypos,IMax(w+1,13),2,lightgray,message);
  270.   Echo_Time_Interval(default,0,precision);
  271.   Window(1,1,80,25);
  272.   end; {Procedure Input_Time_Interval}
  273.  
  274. Function Checksum_Good(line : line_data) : boolean;
  275.   var
  276.     i,checksum,check_digit : integer;
  277.   begin
  278.   checksum := 0;
  279.   for i := 1 to 68 do
  280.     case line[i] of
  281.       '0'..'9' : checksum := checksum + Ord(line[i]) - Ord('0');
  282.            '-' : checksum := checksum + 1;
  283.       end; {case}
  284.   checksum := checksum mod 10;
  285.   check_digit := Ord(line[69]) - Ord('0');
  286.   Checksum_Good := (checksum = check_digit);
  287.   end; {Function Checksums_Good}
  288.  
  289. Function Good_Elements(line : two_line) : boolean;
  290.   var
  291.     result : boolean;
  292.   begin
  293.   result := Checksum_Good(line[1]) and Checksum_Good(line[2]);
  294.   if (line[1,1] <> '1') or
  295.      (line[2,1] <> '2') or
  296.      (Copy(line[1],3,5) <> Copy(line[2],3,5)) then
  297.     result := false;
  298.   if (line[1,24] <> '.') or
  299.      (line[1,35] <> '.') or
  300.      (Copy(line[1],62,3) <> ' 0 ') or
  301.      (line[2,12] <> '.') or
  302.      (line[2,21] <> '.') or
  303.      (line[2,38] <> '.') or
  304.      (line[2,47] <> '.') or
  305.      (line[2,55] <> '.') then
  306.     result := false;
  307.   Good_Elements := result;
  308.   end; {Function Good_Elements}
  309.  
  310. Procedure Input_Satellite(index : word);
  311.   begin
  312.   if not EOF(fsat) then
  313.     begin
  314.     if data_type = 3 then
  315.       Readln(fsat,sat_name[index]);
  316.     Readln(fsat,sat_data[index,1]);
  317.     Readln(fsat,sat_data[index,2]);
  318.     end; {if}
  319.   end; {Procedure Input_Satellite}
  320.  
  321. Function Input_Satellite_Data(fn : string) : word;
  322.   var
  323.     count : word;
  324.   begin
  325.   if data_type in [2,3] then
  326.     begin
  327.     count := 0;
  328.     Assign(fsat,data_drive + data_dir + fn);
  329.     Reset(fsat);
  330.     repeat
  331.       count := count + 1;
  332.       Input_Satellite(count);
  333.     until EOF(fsat) or (count = max_sats);
  334.     Close(fsat);
  335.     Input_Satellite_Data := count;
  336.     end {if}
  337.   else
  338.     begin
  339.     GotoXY(1,24);
  340.     Writeln('Invalid data type!');
  341.     Halt;
  342.     end; {else}
  343.   end; {Procedure Input_Satellite_Data}
  344.  
  345. Procedure Select_Satellites(title : string;
  346.                           x,y,w,h : byte;
  347.                            number : word);
  348.   var
  349.     choice              : char;
  350.     start,stop,select,i : word;
  351.   begin
  352.   Cursor_Off;
  353.   h := IMin(h,number);
  354.   select := 1;
  355.   w := IMax(w,12);
  356.   MakeWindow(x,y,w,h,white,title);
  357.   start := IMin(number - h + 1,select);
  358.   stop  := start + h - 1;
  359.   repeat
  360.     ClrScr;
  361.     for i := start to stop do
  362.       begin
  363.       GotoXY(1,i-start+1);
  364.       if i = select then TextBackground(blue);
  365.       if selected[i] then Write('[*] ') else Write('[ ] ');
  366.       Write(Copy(sat_data[i,1],3,5),'  ',Copy(sat_name[i],1,w-12));
  367.       ClrEOL;
  368.       if i = select then TextBackground(black);
  369.       end; {for i}
  370.     choice := ReadKey;
  371.     if choice = #0 then
  372.       begin
  373.       choice := ReadKey;
  374.       case choice of
  375.           Up : begin
  376.                select := IMax(1,select-1);
  377.                if select < start then
  378.                  begin
  379.                  start := select;
  380.                  stop  := start + h - 1;
  381.                  end; {if}
  382.                end; {Up}
  383.         PgUp : begin
  384.                select := IMax(1,select-h);
  385.                if select < start then
  386.                  begin
  387.                  start := select;
  388.                  stop  := start + h - 1;
  389.                  end; {if}
  390.                end; {PgUp}
  391.           Dn : begin
  392.                select := IMin(number,select+1);
  393.                if select > stop then
  394.                  begin
  395.                  stop  := select;
  396.                  start := stop - h + 1;
  397.                  end; {if}
  398.                end; {Dn}
  399.         PgDn : begin
  400.                select := IMin(number,select+h);
  401.                if select > stop then
  402.                  begin
  403.                  stop  := select;
  404.                  start := stop - h + 1;
  405.                  end; {if}
  406.                end; {PgDn}
  407.         end; {case}
  408.       end {if}
  409.     else
  410.       case UpCase(choice) of
  411.         ' ' : begin
  412.               selected[select] := Not(selected[select]);
  413.               select := IMin(number,select+1);
  414.               if select > stop then
  415.                 begin
  416.                 stop  := select;
  417.                 start := stop - h + 1;
  418.                 end; {if}
  419.               end; {Toggle}
  420.         'A' : begin
  421.               for i := 1 to number do
  422.                 selected[i] := Not(selected[i]);
  423.               end; {Toggle All}
  424.         end; {case}
  425.   until choice = CR;
  426.   Delay(500);
  427.   MakeWindow(x,y,w,h,lightgray,title);
  428.   Window(1,1,80,25);
  429.   end; {Procedure Select_Satellites}
  430.  
  431. Procedure Input_Observer(var geodetic : vector);
  432.   begin
  433.   if not EOF(fobs) then
  434.     begin
  435.     Readln(fobs,obs_name,geodetic[1],geodetic[2],geodetic[3]);
  436.     geodetic[1] := Radians(geodetic[1]);
  437.     geodetic[2] := Radians(Modulus(geodetic[2],360));
  438.     geodetic[3] := geodetic[3]*0.001;
  439.     end; {if}
  440.   end; {Procedure Input_Observer}
  441.  
  442.   begin
  443.   for i := 1 to max_sats do
  444.     selected[i] := false;
  445.  
  446. end.
  447.